import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
import api from '@/api/api'
import store from './store/index'

router.beforeEach((to, from, next) => {
  const title = to.meta.title
  if (title) {
    document.title = title
  }
  next()
})

router.afterEach((to) => {
  document.body.scrollTop = 0
  document.documentElement.scrollTop = 0
})

// naive ui tailwind conflict
function adapterNaiveCss() {
  const meta = document.createElement('meta')
  meta.name = 'naive-ui-style'
  document.head.appendChild(meta)
}
adapterNaiveCss()

const app = createApp(App)
app.use(router)
app.use(store)
app.use(VueAxios, axios)
app.config.globalProperties.$api = api
app.mount('#app')
